using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DoorLocker:MonoBehaviour {

	AutomaticDoorController[] toControl;
	int detectTime;

	private void FixedUpdate() {
		bool isLocked = detectTime>0;
		if(!isLocked) return;
		detectTime--;
		for(int i = 0;i<transform.parent.childCount;i++) {
			Transform other = transform.parent.GetChild(i);
			if(Mathf.Abs(other.position.x-transform.position.x)>3.5f) continue;
			if(Mathf.Abs(other.position.y-transform.position.y)>3.5f) continue;
			AutomaticDoorController target = other.GetComponent<AutomaticDoorController>();
			if(!target) continue;
			target.lockedByLocker=3;
		}

	}

	void OnTriggerStay2D(Collider2D other) {
		Mob otherMob = other.GetComponent<Mob>();
		if((transform.position+new Vector3(0.5f,0.5f)-otherMob.transform.position).sqrMagnitude>0.01f) return;
		if(otherMob!=null) detectTime=2;

	}
}